package com.liangtian.mdm.system.permission.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.liangtian.mdm.base.controller.BaseController;
import com.liangtian.mdm.base.exception.TransactionalException;
import com.liangtian.mdm.base.utils.BrowserUtils;
import com.liangtian.mdm.base.utils.ResultObject;
import com.liangtian.mdm.base.utils.ShiroSessionUtils;
import com.liangtian.mdm.util.RequestUtils;
import com.liangtian.mdm.util.StringUtil;
import com.liangtian.mdm.system.menu.model.Menu;
import com.liangtian.mdm.system.menu.service.MenuService;
import com.liangtian.mdm.system.log.SysLogUtil;
import com.liangtian.mdm.system.log.model.SysLog;
import com.liangtian.mdm.system.log.model.SysLogEnum;
import com.liangtian.mdm.system.log.service.SysLogService;
import com.liangtian.mdm.system.organization.service.SysOrganizationService;
import com.liangtian.mdm.system.permission.model.SysRole;
import com.liangtian.mdm.system.permission.model.SysRoleMenu;
import com.liangtian.mdm.system.permission.service.SysRoleService;
import com.liangtian.mdm.system.user.model.SysUser;
import com.liangtian.mdm.util.ConstantBean;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * <p>Encoding    :  UTF-8</p>
 * <p>Package Name: com.liangtian.mdm.system.permission.controller </p>
 * <p>Project Name: dm </p>
 * <p>Copyright   :  Copyright(c) 2016 石化盈科信息技术有限责任公司 </p>
 * <p>Created Time: 2016-06-15 14:57</p>
 * <p>Description : 角色控制器</p>
 *
 * @author : Administrator
 * @version :  1.0
 */
@Controller
@RequestMapping("/sysRole")
public class SysRoleController extends BaseController {

    //日志
    private static final Logger logger = LoggerFactory.getLogger(SysRoleController.class);

    @Autowired
    MenuService menuService;
    //当前用户
    ////@Value("${ConstantBean.CURRENT_SESSION_USER}")
    //private String ConstantBean.CURRENT_SESSION_USER;

    //机密级别数据字典分类
//    @Value("${PERMISSION_DICT_KIND_ID}")
//    private long PERMISSION_DICT_KIND_ID;

    //注入权限接口对象
    @Autowired
    SysRoleService sysRoleService;

    //注入组织机构服务接口
    @Autowired
    SysOrganizationService sysOrganizationService;

    //日志服务接口对象
    @Autowired
    SysLogService sysLogService;

    //日志model
    SysLog sysLog = new SysLog();

    @ResponseBody
    @RequestMapping(value = "/querBindResourcesList", method = RequestMethod.POST)
    public String querBindResourcesList(HttpServletRequest request, Menu menu) {
        String roleId = request.getParameter("roleId");
        List<Menu> menuLst = new ArrayList<Menu>();
        try {
            menuLst = sysRoleService.getAllmenuTree(); //查询菜单树
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<SysRoleMenu> selectNodeList = sysRoleService.getSelectNode(roleId);
        if (null != selectNodeList && selectNodeList.size() == 0) {
            String jsonStr = JSON.toJSONString(menuLst);
            return jsonStr;
        }
        //对比回显角色关联资源配置
        if (selectNodeList != null && selectNodeList.size() > 0) {
            for (Menu menuselect : menuLst) {
                menuselect.setOpen(false);
                String initMtype = menuselect.getMenu_type();
                String initMid = menuselect.getMenu_id();
                String initModelId = menuselect.getModel_id();
                String nodename = menuselect.getName();
                for (SysRoleMenu sysRoleMenu : selectNodeList) {
                    String selectmodelId = sysRoleMenu.getModelId();
                    String selectmType = sysRoleMenu.getMenuType();
                    String selectMid = sysRoleMenu.getMenuId();
                    if ((StringUtils.isEmpty(selectmodelId) || selectmodelId.equals("")) && (!StringUtils.isEmpty(initMid) && initMid != "" && !initMid.equals(""))) {
                        //走menuID
                        if (selectMid == initMid || selectMid.equals(initMid)) {
                            menuselect.setChecked(true);
                            System.out.println("menuID选中：" + nodename);
                        }
                    } else {
                        //走modelId
                        if (StringUtils.isEmpty(selectmType) || selectmType == "" || selectmType.equals("")) {
                            //二级
                            if (!StringUtils.isEmpty(initModelId) && (initModelId.equals(selectmodelId)) && StringUtils.isEmpty(initMtype)) {
                                menuselect.setChecked(true);
                                System.out.println("二级选中：" + nodename);
                            }
                        } else {
                            //三级
                            if (!StringUtils.isEmpty(initMtype) && !StringUtils.isEmpty(selectmType)) {
                                if ((initModelId.equals(selectmodelId)) && (initMtype.equals(selectmType))) {
                                    menuselect.setChecked(true);
                                    System.out.println("三级选中：" + nodename);
                                }
                            }
                        }

                    }


                }


            }
        }
        String jsonStr = JSON.toJSONString(menuLst);
        return jsonStr;
    }

    @RequestMapping(value = "/saveBindResourcesInfo", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject saveBindResourcesInfo(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        String menuTypes = request.getParameter("menuTypes");
        String menuIds = request.getParameter("menuIds");
        String modelIds = request.getParameter("modelIds");
        String roleId = request.getParameter("roleId");
        String[] mtarray = menuTypes.split(",");
        String[] midarray = menuIds.split(",");
        String[] modelIdarray = modelIds.split(",");
        param.put("mtarray", mtarray);
        param.put("midarray", midarray);
        param.put("modelIdarray", modelIdarray);
        param.put("roleId", roleId);
        boolean ret = false;
        //获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        SysLog sysLog = new SysLog();
        Date date = new Date();
        sysLog.setUserName(user.getUserName());
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        sysLog.setOperationDate(date);
        try {
            ret = sysRoleService.delBindResourcesInfo(roleId);
            if (ret == true) {
                ret = sysRoleService.saveBindResourcesInfo(param);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        SysLogUtil.insertLog("新增角色资源关联关系",
                SysLogEnum.SYS_ROLE_MENU.getCode(), SysLogEnum.XZ.getCode(), request);
        int f = ret == true ? 1 : 0;
        ResultObject result = new ResultObject(f, "新增成功", "新增失败");
        return result;
    }


    @RequestMapping(value = "/deleteRoleUserGroup", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject deleteRoleUserGroup(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        String id = request.getParameter("ids");
        String roleId = request.getParameter("roleId");
        String[] ids = id.split(",");
        List<String> idsList = Arrays.asList(ids);
        param.put("idsList", idsList);
        param.put("roleId", roleId);
        boolean flag = false;
        /*//获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        SysLog sysLog = new SysLog();
        Date date = new Date();
        sysLog.setUserName(user.getUserName());
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        sysLog.setOperationDate(date);*/
        try {
            //删除用户
            flag = sysRoleService.deleteRoleUserGroup(param);
            SysLogUtil.insertLog("删除角色中的用户",
                    SysLogEnum.SYS_USER_ROLE.getCode(), SysLogEnum.SC.getCode(), request);
            //if (count > 0) {
           /*sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",删除角色中的用户成功");
           // }
            //成功记录操作日志
            sysLogServiceImpl.insertLog(sysLog);*/
        } catch (Exception e) {
            /*sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",删除角色中的用户失败");
            //失败记录操作日志
            sysLogServiceImpl.insertLog(sysLog);*/
            e.printStackTrace();
        }
        int f = flag == true ? 1 : 0;
        ResultObject result = new ResultObject(f, "删除角色中的用户成功", "删除角色中的用户失败");
        return result;
    }

    /**
     * 获取未绑定的用户组
     *
     * @param request
     * @param role
     * @return
     * @author hanqing.wang
     */
    @RequestMapping(value = "/queryNoSelUGList", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject queryNoSelUGList(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        PageInfo pageInfo = sysRoleService.queryNoSelUGList(param);
        List l = pageInfo.getList();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rows", l);// JSONArray
        jsonObject.put("total", pageInfo.getTotal());
        return jsonObject;
    }

    /**
     * 获取已配置用户组列表
     *
     * @param role
     * @return
     * @author hanqing.wang
     */
    @RequestMapping(value = "/queryUGRoleList", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject queryUGRoleList(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        PageInfo pageInfo = sysRoleService.queryUGRoleList(param);
        List l = pageInfo.getList();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rows", l);// JSONArray
        jsonObject.put("total", pageInfo.getTotal());
        return jsonObject;
    }

    /**
     * 批量移除用户角色绑定
     *
     * @param request
     * @param role
     * @return
     * @author hanqing.wang
     */
    @RequestMapping(value = "deleteRoleUser", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject deleteRoleUser(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        String id = request.getParameter("ids");
        String roleId = request.getParameter("roleId");
        String[] ids = id.split(",");
        List<String> idsList = Arrays.asList(ids);
        param.put("idsList", idsList);
        param.put("roleId", roleId);
        boolean flag = false;
        try {
            //删除用户
            flag = sysRoleService.deleteRoleUser(param);
        } catch (Exception e) {
            e.printStackTrace();
        }

        SysLogUtil.insertLog("删除角色用户关联关系",
                SysLogEnum.SYS_USER_ROLE.getCode(), SysLogEnum.SC.getCode(), request);
        int f = flag == true ? 1 : 0;
        ResultObject result = new ResultObject(f, "删除角色中的用户成功", "删除角色中的用户失败");
        return result;
    }

    /**
     * 批量给角色绑定用户组
     *
     * @param request
     * @return
     * @author hanqing.wang
     */
    @RequestMapping(value = "/insertRoleUserGroup", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject insertRoleUserGroup(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        String id = request.getParameter("ids");
        String roleId = request.getParameter("roleId");
        String[] ids = id.split(",");
        param.put("ids", ids);
        param.put("roleId", roleId);
        boolean ret = false;
    	/*//获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        SysLog sysLog = new SysLog();
        Date date = new Date();
        sysLog.setUserName(user.getUserName());
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        sysLog.setOperationDate(date);*/
        try {
            ret = sysRoleService.insertRoleUserGroup(param);
            SysLogUtil.insertLog("新增角色用户组关联关系",
                    SysLogEnum.SYS_UGROUP_ROLE.getCode(), SysLogEnum.XZ.getCode(), request);
           /*// if (ret) {
                sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",绑定角色成功");
           // }
            //成功记录操作日志
            sysLogServiceImpl.insertLog(sysLog);*/
        } catch (Exception e) {
            /*sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",绑定角色失败");
            //失败记录操作日志
            sysLogServiceImpl.insertLog(sysLog);*/
            e.printStackTrace();
        }
        int f = ret == true ? 1 : 0;
        ResultObject result = new ResultObject(f, "新增成功", "新增失败");
        return result;
    }

    /**
     * 添加用户角色绑定
     *
     * @param request
     * @param role
     * @return
     * @author hanqing.wang
     */
    @RequestMapping(value = "/insertRoleUser", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject insertRoleUser(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        String id = request.getParameter("ids");
        String roleId = request.getParameter("roleId");
        String[] ids = id.split(",");
        param.put("ids", ids);
        param.put("roleId", roleId);
        boolean ret = false;
    	/*//获取session中用户
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        SysLog sysLog = new SysLog();
        Date date = new Date();
        sysLog.setUserName(user.getUserName());
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        sysLog.setOperationDate(date);*/
        try {
            ret = sysRoleService.insertRoleUser(param);
            SysLogUtil.insertLog("新增角色用户关联关系",
                    SysLogEnum.SYS_USER_ROLE.getCode(), SysLogEnum.XZ.getCode(), request);
           /*// if (ret) {
                sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",绑定角色成功");
           // }
            //成功记录操作日志
            sysLogServiceImpl.insertLog(sysLog);*/
        } catch (Exception e) {
           /* sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",绑定角色失败");
            //失败记录操作日志
            sysLogServiceImpl.insertLog(sysLog);*/
            e.printStackTrace();
        }
        int f = ret == true ? 1 : 0;
        ResultObject result = new ResultObject(f, "新增成功", "新增失败");
        return result;
    }

    @RequestMapping(value = "/queryNoSelUserList", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject queryNoSelUserList(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        PageInfo pageInfo = sysRoleService.queryNoSelUserList(param);
        List l = pageInfo.getList();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rows", l);// JSONArray
        jsonObject.put("total", pageInfo.getTotal());
        return jsonObject;
    }

    /**
     * 获取已配置用户列表
     *
     * @param role
     * @return
     * @author hanqing.wang
     */
    @RequestMapping(value = "/queryUsersRoleList", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject queryUsersRoleList(HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        PageInfo pageInfo = sysRoleService.queryUsersRoleList(param);
        List l = pageInfo.getList();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rows", l);// JSONArray
        jsonObject.put("total", pageInfo.getTotal());
        return jsonObject;
    }

    @RequestMapping(value = "/saveSysRole", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveSysRole(HttpServletRequest request) {
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        JSONObject jsonObject = new JSONObject();
        String roleId = request.getParameter("roleId");
        String roleStatus = request.getParameter("roleStatus");
        String roleFlag = request.getParameter("roleFlag");
        String roleRemark = request.getParameter("roleRemark");
        String roleName = request.getParameter("roleName");
        SysRole role = new SysRole();
        role.setRoleFlag(Integer.parseInt(roleFlag));
        role.setRoleStatus(Integer.parseInt(roleStatus));
        role.setRoleName(roleName);
        role.setRoleRemark(roleRemark);
        if (StringUtil.isBlank(roleId)) {
            role.setCreateUserId(Integer.parseInt(user.getUserId().toString()));
            role.setOrganizationId(Integer.parseInt(user.getOrganizationId().toString()));
            //走插入
            sysRoleService.inseterRole(role);
        } else {
            role.setRoleId(Integer.parseInt(roleId));
            //走保存
            sysRoleService.saveRoleEdit(role);
        }
        try {
            jsonObject.put("resultCode", "0");
        } catch (Exception e) {
            jsonObject.put("resultCode", "-1");
        }
        return jsonObject;
    }

    /**
     * 删除角色包括批量删除
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteByIds(HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        try {
            String idsStr = request.getParameter("ids");
            sysRoleService.deleteByIds(idsStr);
            jsonObject.put("resultCode", "0");
        } catch (Exception e) {
            jsonObject.put("resultCode", "-1");
        }
        return jsonObject;
    }

    /**
     * 获取角色展示列表数据
     * hanqing.wang
     */
    @RequestMapping(value = "/queryAllRoleShowList", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject queryAllRoleShowList(SysRole role, HttpServletRequest request) {
        Map<String, Object> param = RequestUtils.paramToMap(request);
        PageInfo pageInfo = sysRoleService.queryAllRoleShowList(param);
        List l = pageInfo.getList();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("rows", l);// JSONArray
        jsonObject.put("total", pageInfo.getTotal());
        return jsonObject;
    }


    /**
     * @param role 角色对象
     * @desc 查询全部角色信息
     */
    @RequestMapping(value = "/queryAllRoleList", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject queryAllRoleList(SysRole role) {
        PageInfo pageInfo = sysRoleService.queryAllRole(role);
        //返回分页形式
        ResultObject result = new ResultObject(pageInfo, role.getDraw());
        return result;
    }

    /**
     * @param role 角色对象
     * @return 新增角色的结果
     * @desc 新增角色
     */
    @RequestMapping(value = "/insertRole", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject insertRole(SysRole role, Long[] ids, HttpServletRequest request) throws TransactionalException {
        SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        role.setCreateRoleDate((new Date()).toString());
        role.setRoleStatus(1);
        role.setCreateUserId(user.getUserId().intValue());
        int count = sysRoleService.insertRole(role, ids);//新增方法
        /*sysLog.setUserName(user.getUserName());//用户名
        sysLog.setOperationType("3");//操作类型
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        Date date = new Date();//当前时间
        sysLog.setOperationDate(date);
        if (count>0) {
            sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色删除成功");
        }else{
            sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色删除失败");
        }
        sysLogServiceImpl.insertLog(sysLog);*/
        SysLogUtil.insertLog("新增角色",
                SysLogEnum.SYS_ROLE.getCode(), SysLogEnum.XZ.getCode(), request);
        ResultObject resultObject = new ResultObject(count, "新增角色成功", "新增角色失败");
        return resultObject;//返回结果集
    }

    /**
     * @param ids 需要删除的角色的id
     * @return 批量删除后的结果
     * @desc 批量删除角色
     */
    @RequestMapping(value = "/batchDeleteRole", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject batchDeleteRole(Long[] ids, HttpServletRequest request) throws TransactionalException {
        List<Long> idsList = Arrays.asList(ids);
        Map<String, Object> params = new HashMap<>();
        params.put("idsList", idsList);//存放
        int count = sysRoleService.batchDeleteRole(params);//批量删除方法
        SysLogUtil.insertLog("删除角色",
                SysLogEnum.SYS_ROLE.getCode(), SysLogEnum.SC.getCode(), request);
        
       /* SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        sysLog.setUserName(user.getUserName());//用户名
        sysLog.setOperationType("5");//操作类型
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        Date date = new Date();//当前时间
        sysLog.setOperationDate(date);
        if (count>0) {
            sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色删除成功");
        }else {
            sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色删除失败");
        }
        sysLogServiceImpl.insertLog(sysLog);*/
        ResultObject resultObject = new ResultObject(count, "删除成功", "删除失败");
        return resultObject;//返回结果集
    }


    /**
     * @param role 修改角色传递对象
     * @return 修改后的结果
     * @desc 修改角色
     */
    @RequestMapping(value = "/updateRole", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject updateRole(SysRole role, Long[] ids, HttpServletRequest request) throws TransactionalException {
        role.setCreateRoleDate((new Date()).toString());
        int count = sysRoleService.updateRole(role, ids);//编辑方法
        /*SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        sysLog.setUserName(user.getUserName());//用户名
        sysLog.setOperationType("4");//操作类型
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        Date date = new Date();//当前时间
        sysLog.setOperationDate(date);
        if (count>0) {
            sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色编辑成功");
        }else {
            sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色编辑失败");
        }
        sysLogServiceImpl.insertLog(sysLog);*/
        SysLogUtil.insertLog("编辑角色",
                SysLogEnum.SYS_ROLE.getCode(), SysLogEnum.BJ.getCode(), request);
        ResultObject resultObject = new ResultObject(count, "修改成功", "修改失败");
        return resultObject;
    }

    /**
     * @param ids    角色数组
     * @param status 角色状态
     * @return 修改后的结果
     * @desc 修改角色状态
     */
    @RequestMapping(value = "/editRoleStatus", method = RequestMethod.POST)
    @ResponseBody
    public ResultObject editRoleStatus(Long[] ids, Long status, HttpServletRequest request) {
        Map<String, Object> params = new HashMap<>();
        int count = 0;
        List<Long> idsList = Arrays.asList(ids);
        params.put("idsList", idsList);
        params.put("roleStatus", status);
        /*SysUser user = ShiroSessionUtils.getSessionSysUser(ConstantBean.CURRENT_SESSION_USER);
        sysLog.setUserName(user.getUserName());//用户名
        sysLog.setOperationType("4");//操作类型
        sysLog.setBrowserType(BrowserUtils.getBrowserName(request));
        Date date = new Date();//当前时间
        sysLog.setOperationDate(date);*/
        try {
            count = sysRoleService.editRoleStatus(params);
            if (count > 0) {
                if (status == 0) {
                    SysLogUtil.insertLog("角色停用", SysLogEnum.SYS_ROLE.getCode(), SysLogEnum.TY.getCode(), request);
                } else {
                    SysLogUtil.insertLog("角色启用", SysLogEnum.SYS_ROLE.getCode(), SysLogEnum.QY.getCode(), request);
                }
            }
            //sysLogServiceImpl.insertLog(sysLog);
        } catch (Exception e) {
            /*if (status==0) {
                sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色禁用失败");
            }else {
                sysLog.setOperationContent("用户【"+user.getUserName()+"】于"+ DateUtils.dateToString(date,"yyyy-MM-dd HH:mm:ss")+",角色启用失败");
            }
            sysLogServiceImpl.insertLog(sysLog);*/
            e.printStackTrace();
        }
        ResultObject resultObject = new ResultObject(count, "修改角色状态成功", "修改角色状态失败");
        return resultObject;
    }
}
